package cn.tedu.movie.mapper;

import cn.tedu.movie.controller.ActorController;
import cn.tedu.movie.entity.Actor;
import cn.tedu.movie.entity.Movie;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ActorMapper {
    @Select("SELECT id actorId,name name,fans_num fansNum,url actorUrl," +
            "id actorId FROM actor WHERE NAME like concat('%',#{name},'%')")
    List<Actor> searchByName(String name);

    @Select("SELECT a.id actorId,a.name name,fans_num fansNum,a.url actorUrl" +
            ",a.id actorId \n" +
            "FROM `actor` a,`movie` m,`movie_actor` ma\n" +
            "WHERE a.id=ma.actor_id AND m.id=ma.movie_id and m.name like concat('%',#{name},'%')")
    List<Actor> searchActorByMovieName(String name);

//-------------------------后端----------------------------------

    @Select("SELECT a.id actorId,a.name `name`,a.url actorUrl,a.fans_num fansNum\n" +
            ",a.nation nation,a.birthday birthday,a.gender gender,a.height height\n" +
            "FROM `actor` a \n" +
            "WHERE a.name LIKE CONCAT('%',#{name},'%')\n" +
            "order BY a.id limit #{pageNum},#{limit}")
    List<Actor> actorlist(Integer pageNum, Integer limit,String name);
    @Select("select count(*) from `actor` where name like concat('%',#{name},'%')")
    int actorCount(String name);
    @Insert("INSERT INTO `actor` VALUES(NULL,#{name},#{english},#{actorUrl}\n" +
            ",#{gender},'演员',#{nation},0,0,#{birthday},#{intro},#{height})")
    int insertActor(Actor actor);
    @Select("select url from actor where id=#{id}")
    String selectUrlById(Integer id);
    @Delete("delete from actor where id=#{id}")
    int deleteById(Integer id);
    @Select("select id actorId, name name,birthday birthday,height height\n" +
            "from `actor` where id=#{id}")
    Actor selectOne(Integer id);
    @Update("update actor set birthday=#{birthday},height=#{height}\n" +
            "where id=#{actorId}")
    int updateActor(Actor actor);
}
